//index.js
const config = require('../../config.js')
const http = require('../../http.js')
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    winWidth: 0,
    winHeight: 0,
    currentTab: 0,
  },
   

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getSystemInfo( {
      success: function( res ) {
          that.setData( {
              winWidth: res.windowWidth,
              winHeight: res.windowHeight
          });
      }
  });
  this.gettotal();
  this.getyears();
 
  },
//  tab切换逻辑
swichNav: function( e ) {
  var that = this;
  if( this.data.currentTab === e.target.dataset.current ) {
      return false;
  } else {
      that.setData( {
          currentTab: e.target.dataset.current
      })
  }
},

gettotal: function (){
    var that = this
    http.request(
      config.gettotal,
      'get', null,
      function (res) {
        if (res.data!= null) {
          that.setData({
              listData: res.data.ranking,
              total:res.data.integral
          })
        }
      },
      function (err) {
        wx.showToast({
            title: "数据加载失败！",
            icon: 'none',
          })
      } )
  },


  getyears: function () {
    var that = this
    http.request(
      config.getyears,
      'get', null,
      function (res) {
        if (res.data!= null) {
          that.setData({
            itemData:res.data.ranking,
            total:res.data.rowno
          })
        }
      },
      function (err) {
        wx.showToast({
            title: "数据加载失败！",
            icon: 'none',
          })
      } )
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})